package com.ayou.eggguard.farm.controller;

import com.ayou.common.utils.PageBean;
import com.ayou.common.utils.Result;
import com.ayou.eggguard.farm.pojo.ChickenCoop;
import com.ayou.eggguard.farm.pojo.ChickenFarm;
import com.ayou.eggguard.farm.service.ChickenFarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/chickenFarm")
public class ChickenFarmController {
    @Autowired
    private ChickenFarmService chickenFarmService;

    //添加鸡场信息
    @PutMapping("/addFarm")
    public Result addFarm(@RequestBody ChickenFarm chickenFarm){
        ChickenFarm farm=chickenFarmService.getFarmByName(chickenFarm.getFarmName());
        if(farm==null){
            chickenFarmService.addFarm(chickenFarm);
            return Result.success("鸡场添加成功");
        }else{
            return Result.error("鸡场名称已注册");
        }
    }

    //根据鸡场名称修改鸡场信息
    @PutMapping("updateFarm")
    public Result updateFarm(@RequestBody ChickenFarm chickenFarm){
        chickenFarmService.updateFarm(chickenFarm);
        return Result.success("鸡场信息修改成功");
    }

    //查询所有鸡场信息
    @GetMapping("/getAllFarm")
    public Result<List<ChickenFarm>> getAllFarm(){
        List<ChickenFarm> farmList=chickenFarmService.getAllFarm();
        return Result.success(farmList);
    }

}
